package com.whu.service.impl;

import com.whu.dao.CommodityRepository;
import com.whu.pojo.Commodity;
import com.whu.service.CommodityServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityService implements CommodityServiceInterface {

    @Autowired
    CommodityRepository repository;
    @Override
    public List<Commodity> findAll() {
        return repository.findAll();
    }

    @Override
    public Commodity findById(Long id) {
        return repository.findById(id).get();
    }

    @Override
    public List<Commodity> findByName(String commodityName) {
        return repository.findByCommodityName(commodityName);
    }

    @Override
    public void save(Commodity commodity) {
        repository.save(commodity);
    }

    @Override
    public void deleteById(Long id) {
        repository.deleteById(id);
    }
}
